<!DOCTYPE html>
<html>
<head><#include "/admin/common/common.ftl" parse=true encoding="utf-8">
</head>
<body class="hold-transition skin-blue sidebar-mini">
	<div class="wrapper">

		<#include "/admin/common/header.ftl" parse=true encoding="utf-8">

		<!-- Content Wrapper. Contains page content -->
		<div class="content-wrapper">
			<!-- Content Header (Page header) -->
			<section class="content-header">
				<h1>会员管理</h1>
				<ol class="breadcrumb">
					<li class="active">搜索会员</li>
				</ol>
			</section>

			<!-- Main content -->
			<section class="content">
				<div class="row">
					<!-- 搜索 -->


					<!-- 过滤器 -->
					<div class="box col-md-12">
						<ul class="filter-wrapper">
							<form class="form-horizontal" method="post">
								<div class="box-header">
									<h3 class="box-title">搜索条件</h3>
								</div>
								<div class="box-body">
									<div class="form-group">
										<label class="col-md-2 control-label">会员Sn</label>
										<div class="col-md-4 form-control-static">
											<input type="text" id="sn" name="sn" class="form-control" value=""></input>
										</div>
										<label class="col-md-2 control-label">会员账号</label>
										<div class="col-md-4 form-control-static">
											<input type="text" id="username" name="username" class="form-control" value=""></input>
										</div>
									</div>

									<div class="form-group">
										<label class="col-md-2 control-label">会员昵称</label>
										<div class="col-md-4 form-control-static">
											<input type="text" id="nickname" name="nickname" class="form-control" value=""></input>
										</div>
										<label class="col-md-2 control-label">是否已激活</label>
										<div class="col-md-4 form-control-static">
											<input type="radio" name="isActivated" value="true" checked="checked"><span>是</span>
											<input type="radio" name="isActivated" value="false" ><span>否</span>
										</div>
									</div>
									
									<div class="form-group">
										<div class="table-btn col-md-offset-8">
										<a href="javascript:reloadAllData();">
											<span class="label label-primary">搜索</span>
										</a>
									</div>
									</div>

									<div class="form-group">
										<div class="fr"></div>
									</div>
								</div>
								<!-- /.box-body -->
							</form>
					</div>

					<!-- 主要内容 -->
					<div class="box col-md-12">
						<!-- 分页 -->
						<div class="col-md-12">
							<span id="memberList"> </span>
							<div id="pager" style="display: none;"></div>
						</div>
					</div>
				</div>
			</section>
			<!-- /.content -->
		</div>
		<!-- /.content-wrapper -->


	</div>
	<!-- ./wrapper -->
	<#include "/admin/common/footer.ftl" parse=true encoding="utf-8">
</body>
<script type="text/javascript">


	 $(function() {
		resetSearchFilter();
	});
	 
	function fillForm(type, value) {
		var htmlString = "";
		$("#" + type).val(value);
	}

	function resetSearchFilter() {
		var url = "${base}/admin/member/personal/resetSearchFilterAction.json";
		var entity = {};
		window.alert("resetse");
		var onloadFunc = function(result) {

			if (result.isSuccess == true) {
				reloadAllData();
			} else {
				alert(result.message);
			}
		};
		httpRequestPostJson(url, entity, false, onloadFunc);
	}

	function reloadAllData() {
		var url = "${base}/admin/member/personal/reloadDataAction.json";
		var entity = {
			sn : ($("#sn").val().trim().length > 0) ? $("#sn").val().trim()
					: null,
			username : ($("#username").val().trim().length > 0) ? $("#username")
					.val().trim()
					: null,
			nickname : ($("#nickname").val().trim().length > 0) ? $("#nickname")
					.val().trim()
					: null,
			isActivated : $("input[name='isActivated']:checked").val()
		};

		var onloadFunc = function(result) {
			if (result.isSuccess == true) {
				fillData(result.data);
				//	reloadPage(result.pager);
			} else {
				alert(result.message);
			}
		};
		httpRequestPostJson(url, entity, false, onloadFunc);
	}

	function fillData(list) {
		var htmlString = '<div class="box-body "><table id="example1" class="table table-bordered table-striped"><thead><tr>';
		htmlString += '<th>账号</th><th>昵称</th><th>会员类型</th><th>激活状态</th><th>最新登录时间</th><th>登录总次数</th><th>操作</th></tr></thead><tbody>';
		var fillString = '';
		for (var i = 0; i < list.length; i++) {
			var item = list[i];
			fillString += getItemString(item.id, item.sn, item.username,
					item.nickname, item.type, item.isActivated,
					item.lastestLoginTime, item.totalLoginNum);
		}
		if (fillString === null || fillString.length == 0) {
			htmlString = '<div class="col-md-12 text-center"><hr/>暂无记录<hr/></div>';
			$("#pager").hide();
		} else {
			htmlString += fillString;
			$("#pager").show();
		}
		$("#memberList").html(htmlString);
	}

	function getItemString(id, sn, username, nickname, type, isActivated,
			lastestLoginTime, totalLoginNum) {
		var htmlString = '';
		htmlString += '<tr><td>' + username + '</td>';
		htmlString += '<td>' + nickname + '</td>';
		htmlString += '<td>' + type + '</td>';
		htmlString += '<td>' + isActivated + '</td>';
		htmlString += '<td>' + lastestLoginTime + '</td>';
		htmlString += '<td>' + totalLoginNum + '</td>';
		htmlString += '<td>	<a href="javascript:preview(' + "\'"+ sn+"\'"+ ')"><span class="label label-primary">预览</span></a>&nbsp;';
		htmlString += '<a href="javascript:del(' + "\'"+ sn+"\'"+ ')"> <span class="label label-primary">删除</span></a> ';
		htmlString += '</td></tr>';

		return htmlString;
	}

	function preview(sn) {
		window.location = '${base}/admin/member/personal/' + sn + '/preview.do';
	}

	function del(sn) {
		bootbox.setLocale("zh_CN");
		bootbox.confirm("您确认删除选定的记录吗？", function(result) {
			if (result) {
				var url = "${base}/admin/member/personal/delete/" + sn + ".do";
				var entity = {
					sn : sn
				};
				var onloadFunc = function(result) {
					if (result.isSuccess == true) {
						history.go(0);
					} else {
						bootbox.alert("删除失败！");
					}
				};
				httpRequestPostJson(url, entity, false, onloadFunc);
			}
		});
	} 
</script>
</html>

